<?php
class Offline_class_model extends CI_Model{

 	function __construct(){
    	parent::__construct();
	}

  function  get_class_by_id($class_id){
    $sql = "SELECT oc.*,cam.name AS school_name,room.name AS class_room  FROM {$this->db->dbprefix}o2o_class AS oc ";
    $sql .= "LEFT JOIN {$this->db->dbprefix}o2o_school_campus AS cam ON cam.id = oc.campus ";
    $sql .= "LEFT JOIN edu_o2o_classroom room ON room.id = oc.classroom ";
    $sql .= " where oc.id = '{$class_id}' ";
    return $this->db->query($sql)->row_array();
  }

	public function get_class_plan($user_id, $plan_id = 0)
	{
		$sql = "select plan.id,cla.class_name,cla.class_num,plan.class_id,plan.title,plan.class_date,plan.class_time,plan.class_time_str,plan.class_hour,plan.class_type,plan.status,sch.school_name,tea.teacher_name,room.name as class_room_name
		from {$this->db->dbprefix}o2o_class_plan plan
		left join {$this->db->dbprefix}o2o_class cla on cla.id = plan.class_id
		left join {$this->db->dbprefix}o2o_school sch on sch.id=plan.school_id
		left join {$this->db->dbprefix}o2o_teachers tea on tea.id = plan.teacher_id
		left join {$this->db->dbprefix}o2o_classroom room on room.id = plan.class_room
		where plan.class_id in (select cs.class_id from {$this->db->dbprefix}o2o_class_student cs where cs.student_id=(select stu.student_id from {$this->db->dbprefix}o2o_student stu where stu.user_id = {$user_id} limit 1))";
		if($plan_id > 0){
			$sql .= " AND plan.id = '{$plan_id}'";
		}
		return $this->db->query($sql)->result_array();
	}
}
